package uk.co.droidinactu.sony.prst1.home.view;

import uk.co.droidinactu.common.ImageFunctions;
import uk.co.droidinactu.sony.prst1.home.R;
import uk.co.droidinactu.sony.prst1.home.SonyPrsT1HomeApplication;
import uk.co.droidinactu.sony.prst1.home.data.Book;
import uk.co.droidinactu.sony.prst1.home.data.SonyDataModel;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class BookDetailsActivity extends Activity {

    private final static int newWidth = 80;
    private final static int newHeight = 120;

    private ImageView coverImg;
    private TextView bookTitle;
    private TextView bookSeries;
    private TextView bookAuthor;
    private TextView bookPublisher;
    private TextView bookISBN;
    private TextView bookTags;
    private TextView bookSummary;

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.book_details);

        this.coverImg = (ImageView) this.findViewById(R.id.BookDetailsCoverImg);
        this.bookTitle = (TextView) this.findViewById(R.id.BookDetailsTitle);
        this.bookSeries = (TextView) this.findViewById(R.id.BookDetailsSeries);
        this.bookAuthor = (TextView) this.findViewById(R.id.BookDetailsAuthor);
        this.bookPublisher = (TextView) this.findViewById(R.id.BookDetailsPublisher);
        this.bookISBN = (TextView) this.findViewById(R.id.BookDetailsISBN);
        this.bookTags = (TextView) this.findViewById(R.id.BookDetailsTags);
        this.bookSummary = (TextView) this.findViewById(R.id.BookDetailsSummary);

        final SonyPrsT1HomeApplication myApp = (SonyPrsT1HomeApplication) this.getApplication();
        final Book bk = myApp.contextMenuSelectedBook;

        final Bitmap bmp = SonyDataModel.getBookCoverImg(this, bk.file_name);
        this.coverImg.setImageDrawable(new BitmapDrawable(ImageFunctions.scaleImage(bmp, BookDetailsActivity.newWidth,
                BookDetailsActivity.newHeight)));

        this.bookTitle.setText(bk.title, TextView.BufferType.SPANNABLE);

        this.bookAuthor.setText(bk.author.replace("||", " & "), TextView.BufferType.SPANNABLE);

    }

}
